package com.westdream.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.westdream.pojo.Message;
import com.westdream.service.MessageService;
import com.westdream.service.impl.MessageServiceImpl;

public class MessageAction extends Action {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response, Object data) throws ServletException,
			IOException {
		Message msg = (Message)data;
		msg.setAuthor(request.getRemoteAddr());
		MessageService msgService = new MessageServiceImpl();
		try {
			msgService.save(msg);
		} catch(RuntimeException e) {
			e.printStackTrace();
			return "failure";
		}
		return "success";
	}
}
